var GoodsDamageAndOverflow = {
    id: "GoodsDamageAndOverflowTable",
    table: null,
    seItem: null,
    damageAndOverflowData: {},
    layerIndex: -1
}

/**
 * 初始化表格的列
 */
GoodsDamageAndOverflow.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '商品id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '商品编码', field: 'goodsCode', visible: true, align: 'center', valign: 'middle'},
        {title: '商品名称', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
        {title: '商品型号', field: 'goodsModel', visible: true, align: 'center', valign: 'middle'},
        {title: '商品计量单位', field: 'goodsUnit', visible: true, align: 'center', valign: 'middle'},
        {title: '采购价', field: 'goodsPurchasePrice', visible: true, align: 'center', valign: 'middle'},
        {title: '出售价格', field: 'goodsSellingPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '库存数量', field: 'goodsInventoryQuantity', visible: true, align: 'center', valign: 'middle'},
        {title: '库存下限', field: 'goodsMinNum', visible: true, align: 'center', valign: 'middle'},
        {title: '商品上次采购价格', field: 'goodsLastPurchasePrice', visible: false, align: 'center', valign: 'middle'},
        {title: '创建者', field: 'createBy', visible: false, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createDate', visible: false, align: 'center', valign: 'middle'},
        {title: '更新者', field: 'updateBy', visible: false, align: 'center', valign: 'middle'},
        {title: '更新时间', field: 'updateDate', visible: false, align: 'center', valign: 'middle'},
        {title: '备注信息', field: 'remarks', visible: false, align: 'center', valign: 'middle'},
        {title: '删除标记（0：正常；1：删除）', field: 'delFlag', visible: false, align: 'center', valign: 'middle'},
        {title: '供应商名称', field: 'supplierId', visible: false, align: 'center', valign: 'middle'},
        {title: '商品分类id', field: 'goodsCategoryId', visible: false, align: 'center', valign: 'middle'}
    ];
};

/**
 * 初始化表格的列
 */
GoodsDamageAndOverflow.initDamageAndOverflowColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '主键', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '单据', field: 'orderNumber', visible: false, align: 'center', valign: 'middle'},
        {
            title: '报损单据',
            field: 'damageOrderNumber',
            visible: true,
            align: 'center',

            valign: 'middle'
        },
        {
            title: '报溢单据',
            field: 'overflowOrderNumber',
            visible: true,
            align: 'center',
            valign: 'middle'
        },
        {title: '创建者', field: 'createBy', visible: true, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createDate', visible: true, align: 'center', valign: 'middle'},
        {title: '更新者', field: 'updateBy', visible: false, align: 'center', valign: 'middle'},
        {title: '更新时间', field: 'updateDate', visible: false, align: 'center', valign: 'middle'},
        {title: '备注信息', field: 'remarks', visible: true, align: 'center', valign: 'middle'},
        {title: '删除标记（0：正常；1：删除）', field: 'delFlag', visible: false, align: 'center', valign: 'middle'}
    ];
};


/**
 * 检查是否选中
 */
GoodsDamageAndOverflow.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length === 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        GoodsDamageAndOverflow.seItem = selected[0];
        return true;
    }
};

/**
 * 搜索按钮
 */
GoodsDamageAndOverflow.search = function () {
    var queryData = {};
    queryData['orderNumber'] = $("#orderNumber").val();
    queryData['queryType'] = $("#queryType").val();
    GoodsDamageAndOverflow.table.refresh({query: queryData});
}

/**
 * 搜索清除
 */
GoodsDamageAndOverflow.clear = function () {
    $("#orderNumber").val('');
}


/**
 * 打开订单详情
 */
GoodsDamageAndOverflow.openOrderDetailIndex = function () {
    if (this.check()) {

        var id = GoodsDamageAndOverflow.seItem.id;
        var damageOrderNumber = GoodsDamageAndOverflow.seItem.damageOrderNumber;
        var overflowNumber =GoodsDamageAndOverflow.seItem.overflowOrderNumber;

        var orderNumber = '';
        var queryType = 0;
        if(typeof damageOrderNumber !== 'undefined' && damageOrderNumber.indexOf('BS') > -1){
            orderNumber = damageOrderNumber;
            queryType = 1;
        }
        if(typeof overflowNumber !== 'undefined' && overflowNumber.indexOf('BY') > -1){
            orderNumber = overflowNumber;
            queryType = 2;
        }
        if(orderNumber === '' || queryType === 0){
            return;
        }
        console.log('orderNumber',orderNumber);
        console.log('queryType',queryType);
        var index = layer.open({
            type: 2,
            title: '商品单据详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/managerGoods/goodsDamageAndOverflowOrder/index/' + id + '/' + queryType + '/' + orderNumber
        });
        this.layerIndex = index;
    }
}

$(function () {
    var defaultColumns = GoodsDamageAndOverflow.initDamageAndOverflowColumn();
    var table = new BSTable(GoodsDamageAndOverflow.id, "/managerGoods/goodsDamageAndOverflow/list", defaultColumns);
    table.setQueryParams({"queryType": 1});
    GoodsDamageAndOverflow.table = table.init();
})